﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VirtualPress.Infrastructure.Entities.Repository;
using VirtualPress.Infrastructure.Entities.Enum;

namespace VirtualPress.Infrastructure.Entities.Entity
{
    public class Author : IAccessible<T_Author, Author>, ILogicEntity<T_Author, Author>
    {
        #region Fileds
        public int Id { get; set; }
        public string UserName { get; set; }
        /// <summary>
        /// 名
        /// </summary>
        public string FirstName { get; set; }
        /// <summary>
        /// 姓
        /// </summary>
        public string LastName { get; set; }
        /// <summary>
        /// 联系邮箱
        /// </summary>
        public string Email { get; set; }
        /// <summary>
        /// 性别
        /// </summary>
        public Gender Gender { get; set; }
        /// <summary>
        /// 单位
        /// </summary>
        public string Department { get; set; }
        /// <summary>
        /// 单位英文
        /// </summary>
        public string Department_EN { get; set; }
        /// <summary>
        /// 称谓
        /// </summary>
        public string Title { get; set; }
        /// <summary>
        /// 称谓英文
        /// </summary>
        public string Title_EN { get; set; }
        /// <summary>
        /// 作者简介
        /// </summary>
        public string Introduction { get; set; }
        /// <summary>
        /// 作者简介英文
        /// </summary>
        public string Introduction_EN { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }
        /// <summary>
        /// 查稿密码
        /// </summary>
        public string CheckPassword { get; set; }
        /// <summary>
        /// 详细地址
        /// </summary>
        public string Address { get; set; }
        /// <summary>
        /// 邮政编码
        /// </summary>
        public string PostCode { get; set; }
        /// <summary>
        /// 国籍
        /// </summary>
        public int Country { get; set; }
        /// <summary>
        /// 学位
        /// </summary>
        public string Degree { get; set; }
        public string Phone { get; set; }
        #endregion

        protected override void Covariant(T_Author model)
        {
            if (model != null)
            {
                this.CreateTime = model.CreateTime;
                this.Department = model.Department;
                this.Department_EN = model.Department_EN;
                this.Gender = model.Gender ? Enum.Gender.Male : Enum.Gender.Female;
                this.Introduction = model.Introduction;
                this.Introduction_EN = model.Introduction_EN;
                this.FirstName = model.FirstName;
                this.LastName = model.LastName;
                this.Title = model.Title;
                this.Title_EN = model.Title_EN;
                this.UserName = model.UserName;
                this.CheckPassword =model.CheckPassword;
                this.Address=model.Address;
                this.PostCode=model.PostCode;
                this.Country = model.Country;
                this.Degree=model.Degree;
                this.Email = model.Email;
                this.Id = model.Id;
                this.Phone = model.Phone;
            }
        }
        protected override T_Author Inverter(Author model)
        {
            if (model != null)
            {
                return new T_Author()
                {
                    CreateTime = model.CreateTime,
                    Department = model.Department,
                    Department_EN = model.Department_EN,
                    Gender = model.Gender == Enum.Gender.Male,
                    Introduction = model.Introduction,
                    Introduction_EN = model.Introduction_EN,
                    FirstName=model.FirstName,
                    LastName=model.LastName,
                    Title = model.Title,
                    Title_EN = model.Title_EN,
                    UserName = model.UserName,
                    Address = model.Address,
                    CheckPassword = model.CheckPassword,
                    Country = model.Country,
                    Degree = model.Degree,
                    PostCode = model.PostCode,
                    Email =model.Email,
                    Id = model.Id,
                    Phone=model.Phone
                };
            }
            return null;
        }

        public Author Set(T_Author dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
